package com.javabasic.algorithm.leetcode;

import org.junit.Test;

import java.util.Random;

/**
 * @Author xiongmin
 * @Description
 * @Date 2021/1/20 12:48
 * @Version 1.0
 * @TODO
 **/
public class MaximumProductOfThreeNumbers {

    public static void main(String[] args) {

    }

    @Test
    public void test() {
        Random random = new Random();
        int len = 10;
        int[] array = new int[len];
        for (int j = 0; j < len; j++) {
            System.out.println("======第" + j + "次测试BEGIN=======");
            for (int i = 0; i < len; i++) {
                array[i] = random.nextInt(100);
                System.out.print(array[i] + " ");
            }
            System.out.println();
            quickSort(array,0,len-1);
            for (int num : array) {
                System.out.print(num + " ");
            }
            System.out.println();
            System.out.println("======第" + j + "次测试END  =======");
        }

    }

    public int maximumProduct(int[] nums) {
        int length = nums.length;
        int result = 1;
        if (length <= 3) {
            for (int i = 0; i < length; i++) {
                result *= nums[i];
            }
        } else {

        }
        return result;
    }

    private void quickSort(int[] nums, int left, int right) {
        if (left < right) {
            int mid = execSort(nums,left,right);
            quickSort(nums,left,mid-1);
            quickSort(nums,mid+1,right);
        }
    }

    private int execSort(int[] nums, int left, int right) {
        int tag = nums[left];
        while (left < right) {
            while (nums[right] >= tag && left < right) {
                right--;
            }
            nums[left] = nums[right];
            while (nums[left] < tag && left < right) {
                left++;
            }
            nums[right] = nums[left];
        }
        nums[left] = tag;
        return left;
    }
}
